#include<iostream>
#include<string.h>

using std::cout;
using std::endl;
using std::cin;

class String
{
public:
    union Buffer
    {
        char arr[16];
        char* _pstr;
    };

    class Charproxy
    {
    public:
        Charproxy( String& lhs,int idx)
            :_str(lhs)
             ,_idx(idx)
        {
        }
    private:
        String& _str;
        int _idx;
    };

public:
    String()
        :_size(16)
         ,_capacity(16)
    {
    }
    char* malloc(const char* lhs)
    {
        char *p=new char[kNum+strlen(lhs)+1]()+kNum;
        *(int*)(p-kNum)=1;
        return p;
    }

    void addnum()
    {
        if(_size>15)
        {
        ++*(int*)(_buffer._pstr-kNum);
        }
    }
    void subnum()
    {
        if(_size>15)
        {
        --*(int*)(_buffer._pstr-kNum);
        }
    }
    String(const char* lhs)
        :_size(16)
         ,_capacity(16)
    {
    size_t size=strlen(lhs);
    if(size>15)
    {
        _buffer._pstr=new char[size+1]();
        _size=size;
        _capacity=size;
    }
    else 
    {
        strcpy(_buffer.arr,lhs);
        _size=size;
    }
    }
    
private:
    int _size;
    int _capacity;
    Buffer _buffer;
    static const int kNum=4;
};
